package com.dayu.gulimall.auth;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;


/**
 * springsession 核心原理
 * 1、@EnableRedisHttpSession导入了@RedisHttpSessionConfiguration配置类
 *      1、1、给容器添加了组件RedisIndexedSessionRepository sessionRepository： redis操作怎删改查的类
 *      2、导入了SessionRepositoryFilter ：Filter： session存储过滤器，每个请求都经过这个filter
 *
 *     ---------------------------核心方法--------------------------------------------------
 *        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
 *         request.setAttribute(SESSION_REPOSITORY_ATTR, this.sessionRepository);
 *         封装过的request
 *         SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryFilter.SessionRepositoryRequestWrapper(request, response);
 *         封装过的response
 *         SessionRepositoryFilter.SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryFilter.SessionRepositoryResponseWrapper(wrappedRequest, response);
 *
 *         try {
 *             filterChain.doFilter(wrappedRequest, wrappedResponse);
 *         } finally {
 *             wrappedRequest.commitSession();
 *         }
 *     }
 *     -----------------------------------------------------------------------------
 *    2.1、创建的时候就自动获取了SessionRepository，
 *    2.2、原始的request，response都是包装过了，SessionRepositoryRequestWrapper，SessionRepositoryResponseWrapper
 *    2.3、以后获取session，request.getSession() 其实都是通过包装类获取的session
 *    2.4、 requestedSession.getSession();SessionRepository  这里的SessionRepository就是1.1中的SessionRepository就是获取redis中的数据
 *
 * 原理就是：装饰者模式
 *
 */
@EnableRedisHttpSession
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class GulimallAuthServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(GulimallAuthServerApplication.class, args);
    }

}
